// IncomeTaxController.java
package com.example.controller;

import com.example.model.IncomeTaxRequest;
import com.example.model.IncomeTaxResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IncomeTaxController {

    @PostMapping("/income-tax")
    public IncomeTaxResult calculateIncomeTax(@RequestBody IncomeTaxRequest request) {
        double income = request.getIncome();
        double tax = calculateTax(income);

        IncomeTaxResult result = new IncomeTaxResult();
        result.setTaxAmount(tax);

        return result;
    }

    private double calculateTax(double income) {
        // 计算个人所得税的逻辑
        double tax = 0.0;
        // 这里只是一个简化的示例，具体的计算逻辑可能更复杂
        if (income <= 5000) {
            tax = 0.0;
        } else if (income <= 10000) {
            tax = income * 0.1;
        } else if (income <= 20000) {
            tax = income * 0.2;
        } else {
            tax = income * 0.3;
        }
        return tax;
    }

}
